<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/7/7
 * Time: 9:52
 */

namespace pay\libs;


use app\models\ErrorMsg;

class Msg
{
    private $operation;


    public function __construct()
    {
        if (empty($app_id)){
            $app_id = 0;
        }
        $this->operation = $app_id;
    }

    /*** 插入报错数据
     * @param $url
     * @param $code
     * @param string $data
     * @return bool
     */
    public  function insertMsg($code,$data = '',$msg = '')
    {
        if (!empty($msg)){
            $msgData = $msg;
        }else{
            $msgData = $this->getMsg($code);
        }

        $paramsDate = [
            'ErrorMsg' => [
                'url' => \Yii::$app->request->userIP,
                'code' => $code,
                'msg' => $msgData,
                'data' => $data,
                'operation' => (string)$this->operation,
                'create_time' => date("Y-m-d H:i:s"),
            ]
        ];
        $errorModel = new ErrorMsg();
        $res = $errorModel->addInfo($paramsDate);
        return $res;

    }


    public function getMsg($code)
    {
        $msgList = [
            '10035' => '请登录系统',
            '10045' => '数据存储失败',
            '10055' => '参数缺失',
            '10235' => '参数异常',
        ];
        $msg = $msgList[$code];
        if (empty($msg)){
            return '参数有误';
        }
        return $msg;
    }


}